home *** CD-ROM | disk | FTP | other *** search
/ 3D Games - Real-time Rend…ng & Software Technology / 3D Games - Real-time Rendering & Software Technology.iso / flysdk / util / flyPlugin / cstm1dlg.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2000-05-12  |  8.2 KB  |  298 lines

  1. // cstm1dlg.cpp : implementation file
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "flyplugin.h"
  6. #include "chooser.h"
  7. #include "cstm1dlg.h"
  8. #include "cstm2dlg.h"
  9. #include "flypluginaw.h"
  10.  
  11. #ifdef _PSEUDO_DEBUG
  12. #undef THIS_FILE
  13. static char THIS_FILE[] = __FILE__;
  14. #endif
  15.  
  16. char str_num_classes[256];
  17. char str_get_class_desc[512];
  18. char *buf_img1=0;
  19. BITMAPINFO bmi;
  20. char classes_names[MAX_CLASSES][64];
  21. int num_classes;
  22.  
  23. /////////////////////////////////////////////////////////////////////////////
  24. // CCustom1Dlg dialog
  25.  
  26.  
  27. CCustom1Dlg::CCustom1Dlg()
  28.     : CAppWizStepDlg(CCustom1Dlg::IDD)
  29. {
  30.     //{{AFX_DATA_INIT(CCustom1Dlg)
  31.     //}}AFX_DATA_INIT
  32. }
  33.  
  34.  
  35. void CCustom1Dlg::DoDataExchange(CDataExchange* pDX)
  36. {
  37.     CAppWizStepDlg::DoDataExchange(pDX);
  38.     //{{AFX_DATA_MAP(CCustom1Dlg)
  39.     DDX_Control(pDX, IDC_CLASSES, m_classes);
  40.     DDX_Control(pDX, IDC_CLASSNAME, m_classname);
  41.     //}}AFX_DATA_MAP
  42. }
  43.  
  44. // This is called whenever the user presses Next, Back, or Finish with this step
  45. //  present.  Do all validation & data exchange from the dialog in this function.
  46. BOOL CCustom1Dlg::OnDismiss()
  47. {
  48.     if (!UpdateData(TRUE))
  49.         return FALSE;
  50.  
  51.     char str[512], str2[512], str3[512];
  52.     static char buf1[2048], buf2[2048], buf3[2048], buf4[2048], buf5[4096], buf6[8192];
  53.     buf1[0]=0; buf2[0]=0; buf3[0]=0, buf4[0]=0; buf5[0]=0; buf6[0]=0;
  54.  
  55.     int i,j=m_classes.GetCount();
  56.     sprintf(str_num_classes,"\treturn %i;\n",j);
  57.     num_classes=j;
  58.  
  59.     strcpy(buf3,"enum\n{\n");
  60.     
  61.     str_get_class_desc[0]=0;
  62.     for( i=0;i<j;i++ )
  63.     {
  64.         m_classes.GetText(i,str);
  65.         strcpy(classes_names[i],str);
  66.         strcat(buf1,str);
  67.         strcat(buf1,"\n");
  68.         
  69.         sprintf(str2,"%s_desc cd_%s;\n",str, str);
  70.         strcat(buf2,str2);
  71.  
  72.         sprintf(str2, "\tcase %i:\n", i);
  73.         strcat(str_get_class_desc, str2);
  74.         sprintf(str2, "\t\treturn &cd_%s;\n", str);
  75.         strcat(str_get_class_desc, str2);
  76.  
  77.         strcpy(str3,str);
  78.         strupr(str3);
  79.         sprintf(str2,"\tTYPE_%s%s\n",str3,(i==0 ? "=100000," : ","));
  80.         strcat(buf3,str2);
  81.  
  82.         sprintf(str2,"class %s_desc : public class_desc\n{\npublic:\n\tvoid *create() { return new %s; };\n\tchar *get_name() { return \"%s\"; };\n\tint get_type() { return TYPE_%s; };\n};\n",str,str,str,str3);
  83.         strcat(buf4,str2);
  84.  
  85.         sprintf(str2,"class %s : public bsp_object\n{\npublic:\n\t%s() { type=TYPE_%s; };\n\tint step(int dt);\n\tvoid draw();\n\tint get_custom_param_desc(int i,param_desc *pd);\n\tbsp_object *clone();\n};\n",str,str,str3);
  86.         strcat(buf5,str2);
  87.  
  88.         sprintf(str2,"void %s::step(int dt)\n{\n\t// TODO: animate dt milliseconds\n}\n\n",str);
  89.         strcat(buf6,str2);
  90.         sprintf(str2,"void %s::draw()\n{\n\t// TODO: draw using opengl\n}\n\n",str);
  91.         strcat(buf6,str2);
  92.         sprintf(str2,"bsp_object *%s::clone()\n{\n\t%s *tmp=new %s;\n\t*tmp=*this;\n\ttmp->source=this;\n\treturn tmp;\n}\n\n",str,str,str);
  93.         strcat(buf6,str2);
  94.         sprintf(str2,"int %s::get_custom_param_desc(int i,param_desc *pd)\n{\n\tif (pd!=0)\n\tswitch(i)\n\t{\n\tcase 0:\n\t\t// TODO: pd->type=PARAM_TYPE;\n\t\t// TODO: pd->data=&PARAM_DATA;\n\t\t// TODO: strcpy(pd->name,\"param_name\");\n\t\tbreak;\n\t}\n\treturn 0; // return number of parameters\n}\n\n",str);
  95.         strcat(buf6,str2);
  96.     }
  97.  
  98.     strcat(buf3,"};\n");
  99.  
  100.     Flypluginaw.m_Dictionary["CLASSES"]=buf1;
  101.     Flypluginaw.m_Dictionary["CLASS_DESC"]=buf2;
  102.     Flypluginaw.m_Dictionary["ENUM"]=buf3;
  103.     Flypluginaw.m_Dictionary["CLSSESDESC_H"]=buf4;
  104.     Flypluginaw.m_Dictionary["CLASSES_H"]=buf5;
  105.     Flypluginaw.m_Dictionary["CLASSES_CPP"]=buf6;
  106.     
  107.     int dllnum=1;
  108.     buf1[0]=0;
  109.  
  110.     sprintf(str,"num_classes\t@%i\n",dllnum++);
  111.     strcat(buf1,str); str[0]=0;
  112.     strcat(str,"__declspec( dllexport )\n");
  113.     strcat(str,"int num_classes()\n");
  114.     strcat(str,"{\n");
  115.     strcat(str,str_num_classes);
  116.     strcat(str,"}\n");
  117.     Flypluginaw.m_Dictionary["NUM_CLASSES"]=str;
  118.     sprintf(str,"get_class_desc\t@%i\n",dllnum++);
  119.     strcat(buf1,str); str[0]=0;
  120.     strcat(str,"__declspec( dllexport )\n");
  121.     strcat(str,"class_desc *get_class_desc(int i)\n");
  122.     strcat(str,"{\n");
  123.     strcat(str,"\tswitch(i)\n");
  124.     strcat(str,"\t{\n");
  125.     strcat(str,str_get_class_desc);
  126.     strcat(str,"\tdefault: return 0;\n");
  127.     strcat(str,"\t}\n");
  128.     strcat(str,"}\n");
  129.     Flypluginaw.m_Dictionary["GET_CLASS_DESC"]=str;
  130.     sprintf(str,"fly_message\t@%i\n",dllnum++);
  131.     strcat(buf1,str); str[0]=0;
  132.     strcat(str,"__declspec( dllexport )\n");
  133.     strcat(str,"int fly_message(int msg,int param,void *data)\n");
  134.     strcat(str,"{\n");
  135.     strcat(str,"\tswitch(msg)\n");
  136.     strcat(str,"\t{\n");
  137.     strcat(str,"\tcase FLYM_UPDATESCENE:\n");
  138.     strcat(str,"\t\t// step plugin (dt in param)\n");
  139.     strcat(str,"\t\tbreak;\n");
  140.     strcat(str,"\tcase FLYM_DRAWSCENE:\n");
  141.     strcat(str,"\t\t// draw 3d plugin\n");
  142.     strcat(str,"\t\tbreak;\n");
  143.     strcat(str,"\tcase FLYM_DRAWTEXT:\n");
  144.     strcat(str,"\t\t// draw 2d plugin\n");
  145.     strcat(str,"\t\tbreak;\n");
  146.     strcat(str,"\tcase FLYM_INITSCENE:\n");
  147.     strcat(str,"\t\t// scene load: init plugin\n");
  148.     strcat(str,"\t\tbreak;\n");
  149.     strcat(str,"\tcase FLYM_CLOSESCENE:\n");
  150.     strcat(str,"\t\t// scene close: free plugin\n");
  151.     strcat(str,"\t\tbreak;\n");
  152.     strcat(str,"\t}\n");
  153.     strcat(str,"\treturn 1;\n");
  154.     strcat(str,"}\n");
  155.     Flypluginaw.m_Dictionary["FLY_MESSAGE"]=str;
  156.  
  157.     Flypluginaw.m_Dictionary["FUNCTIONS"]=buf1;
  158.  
  159.     if (((CCustom2Dlg *)Flypluginaw.m_pChooser->m_pDlgs[2])->m_hWnd)
  160.         ((CCustom2Dlg *)Flypluginaw.m_pChooser->m_pDlgs[2])->InitDialog();
  161.  
  162.     return TRUE;    // return FALSE if the dialog shouldn't be dismissed
  163. }
  164.  
  165.  
  166. BEGIN_MESSAGE_MAP(CCustom1Dlg, CAppWizStepDlg)
  167.     //{{AFX_MSG_MAP(CCustom1Dlg)
  168.     ON_BN_CLICKED(IDC_ADD, OnAdd)
  169.     ON_BN_CLICKED(IDC_REMOVE, OnRemove)
  170.     ON_BN_CLICKED(IDC_UP, OnUp)
  171.     ON_BN_CLICKED(IDC_DOWN, OnDown)
  172.     ON_WM_PAINT()
  173.     //}}AFX_MSG_MAP
  174. END_MESSAGE_MAP()
  175.  
  176.  
  177. /////////////////////////////////////////////////////////////////////////////
  178. // CCustom1Dlg message handlers
  179.  
  180. void CCustom1Dlg::OnAdd() 
  181. {
  182.     char str[255];
  183.     m_classname.GetWindowText(str,255);
  184.     if (str[0])
  185.     {
  186.         int i=m_classes.InsertString(-1,str);
  187.         m_classes.SetCurSel(i);
  188.         m_classname.SetWindowText("");
  189.     }
  190.     m_classname.SetFocus();
  191. }
  192.  
  193. void CCustom1Dlg::OnRemove() 
  194. {
  195.     int i=m_classes.GetCurSel();
  196.     if (i!=-1)
  197.         m_classes.DeleteString(i);
  198. }
  199.  
  200. void CCustom1Dlg::OnUp() 
  201. {
  202.     int i=m_classes.GetCurSel();
  203.     if (i==0)
  204.         return;
  205.     char str[256];
  206.     m_classes.GetText(i,str);
  207.     m_classes.DeleteString(i);
  208.     m_classes.InsertString(i-1,str);
  209.     m_classes.SetCurSel(i-1);
  210. }
  211.  
  212. void CCustom1Dlg::OnDown() 
  213. {
  214.     int i=m_classes.GetCurSel();
  215.     if (i==m_classes.GetCount()-1)
  216.         return;
  217.     char str[256];
  218.     m_classes.GetText(i,str);
  219.     m_classes.DeleteString(i);
  220.     m_classes.InsertString(i+1,str);
  221.     m_classes.SetCurSel(i+1);
  222. }
  223.  
  224. void CCustom1Dlg::OnPaint() 
  225. {
  226.     CPaintDC dc(this); 
  227.  
  228.     RECT rect;
  229.     GetClientRect(&rect);
  230.  
  231.     CBrush brush(RGB(96,96,96));
  232.     rect.right=180;
  233.     dc.FillRect(&rect,&brush);
  234.  
  235.     dc.SelectObject(GetStockObject(BLACK_PEN));
  236.  
  237.     dc.MoveTo(rect.right,0);
  238.     dc.LineTo(rect.right,rect.bottom);
  239.  
  240.     if (buf_img1==0)
  241.     {
  242.     HRSRC res=FindResource(hInst,"IMG1","TEMPLATE");
  243.     if (res)
  244.         {
  245.         HGLOBAL hg=LoadResource(hInst,res);
  246.         if (hg)
  247.             {
  248.             buf_img1=(char *)LockResource(hg);
  249.             if (buf_img1)
  250.                 {
  251.                 bmi.bmiHeader.biSize=sizeof(BITMAPINFOHEADER);
  252.                 bmi.bmiHeader.biWidth=128;
  253.                 bmi.bmiHeader.biHeight=128;
  254.                 bmi.bmiHeader.biPlanes=1;
  255.                 bmi.bmiHeader.biBitCount=24;
  256.                 bmi.bmiHeader.biCompression=BI_RGB;
  257.                 bmi.bmiHeader.biSizeImage=0;
  258.                 bmi.bmiHeader.biXPelsPerMeter=3600;
  259.                 bmi.bmiHeader.biYPelsPerMeter=3600; 
  260.                 bmi.bmiHeader.biClrUsed=0;     
  261.                 bmi.bmiHeader.biClrImportant=0; 
  262.                 }
  263.             }
  264.         }
  265.     }
  266.     if (buf_img1)
  267.         SetDIBitsToDevice(dc.m_hDC,
  268.             rect.right/2-64,32,128,128,
  269.             0,0,0,128,
  270.             &buf_img1[18],&bmi,DIB_RGB_COLORS);
  271. }
  272.  
  273. BOOL CCustom1Dlg::OnInitDialog() 
  274. {
  275.     CAppWizStepDlg::OnInitDialog();
  276.     
  277.     static int i=0;
  278.     if (i==0)
  279.     {
  280.     Flypluginaw.m_Dictionary["CLASSES"]="";
  281.     Flypluginaw.m_Dictionary["CLASS_DESC"]="";
  282.     Flypluginaw.m_Dictionary["ENUM"]="";
  283.     Flypluginaw.m_Dictionary["CLSSESDESC_H"]="";
  284.     Flypluginaw.m_Dictionary["CLASSES_H"]="";
  285.     Flypluginaw.m_Dictionary["CLASSES_CPP"]="";
  286.  
  287.     Flypluginaw.m_Dictionary["NUM_CLASSES"]="";
  288.     Flypluginaw.m_Dictionary["GET_CLASS_DESC"]="";
  289.     Flypluginaw.m_Dictionary["FLY_MESSAGE"]="";
  290.     Flypluginaw.m_Dictionary["FUNCTIONS"]="";
  291.  
  292.     Flypluginaw.m_Dictionary["FLYSDKPATH"]="\\FlySDK\\";
  293.  
  294.     i=1;
  295.     }
  296.     return TRUE;
  297. }
  298.